package com.ganee.agora.viewmodel

import android.app.Application
import android.content.Intent
import androidx.lifecycle.MutableLiveData
import com.alibaba.android.arouter.launcher.ARouter

import com.ganee.agora.repository.LoginRepository
import com.ganee.agora.repository.OriginalLoginRepository
import com.ganee.baselib.arouter.Constance
import com.ganee.baselib.httprequest.cache.ACache
import com.ganee.baselib.httprequest.cache.EnumKey
import com.ganee.baselib.httprequest.callback.RequestCallback
import com.ganee.baselib.httprequest.callback.RequestMultiplyCallback
import com.ganee.baselib.httprequest.exception.ApiException
import com.ganee.baselib.httprequest.utils.ToastUtil
import com.ganee.baselib.httprequest.utils.Utils
import com.ganee.baselib.mvvmlibrary.base.BaseViewModel

import okhttp3.RequestBody

class OriginalLoginViewModel(application: Application) : BaseViewModel<OriginalLoginRepository>(application) {

    override fun getRepository(): OriginalLoginRepository {
        return OriginalLoginRepository(this)
    }

    //接口的请求数据以及回调
    fun login(body: RequestBody) {
        mRepository.login(body, RequestCallback<String> { token ->
            ACache.get(Utils.getContext().applicationContext).put(EnumKey.User.USER_TOKEN, token)
            ARouter.getInstance()
                    .build(Constance.ACTIVITY_URL_MAIN)
                    .withFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)
                    .navigation()
        })
    }

}
